package com.young.hzh_learning;

import android.app.Activity;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.widget.Toast;

/**
 * 安卓晃动手机监听--“摇一摇”
 *
 * @author 单红宇
 */
public class TestSensorActivity extends Activity {

    private Vibrator vibrator;

    private static final String TAG = "TestSensorActivity";

    private ShakeListener mShakeListener = new ShakeListener(this, -1);

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

        mShakeListener.setOnShakeListener(new ShakeListener.OnShakeListener() {
            @Override
            public void onShake() {
                vibrator.vibrate(200);
                Toast.makeText(TestSensorActivity.this, "检测到摇晃，执行操作！", Toast.LENGTH_SHORT).show();
                Log.i(TAG, "检测到摇晃，执行操作！");
                Log.e("young_test909090", "tiankon");
            }
        });

        mShakeListener.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}